import {
  imageUrl
} from "../../utils/imageutil"

Page({
  data: {
    imageUrl,

    name: '',

    shopInfo: wx.getStorageSync('merchant').admin,
    list: [],
    page: 1,
    limit: 10,
    flag: true,
    showmask: false,
    checkList: [],
    work_id: '',
  },
  onLoad(options) {

    this.setData({
      work_id: options.work_id,
    })

    this.getauntList()
  },
  onPullDownRefresh() {
    this.setData({
      page: 1,
      flag: true,
      list: [],
    })
    this.getauntList()
  },
  onReachBottom() {
    return
    this.getauntList()
  },
  getauntList() {

    if (!this.data.flag) {
      return
    }
    this.setData({
      flag: false
    })
    getApp().globalData.gets('/api/app/work/sorting/ouyoung_api/rechouse', {
      work_id:this.data.work_id
    }).then(res => {
      wx.stopPullDownRefresh()
      if (res.data.data.list.length == 0) {
        this.setData({
          flag: false
        })
      } else {
        let arr = this.data.list.concat(res.data.data.list);
        this.setData({
          list: arr,
          page: this.data.page + 1,
          flag: true
        })
      }
    })
  },
  change_ckeck(e) {
    let val = e.currentTarget.dataset.id
    this.data.list.forEach((v, i) => {
      this.setData({
        ['list[' + i + '].check']: false
      })
      if (v.id == val) {
        this.setData({
          ['list[' + i + '].check']: true
        })
      }
    })
  },
  bottomTaps() {
    let arr = []
    this.data.list.forEach((v, i) => {
      if (v.check) {
        arr.push(v)
      }
    })
    this.setData({
      checkList: arr
    })
    if (this.data.checkList.length > 0) {
      this.setData({
        showmask: true
      })
    } else {
      wx.showToast({
        title: '请选择家政员',
        icon: "none"
      })
    }
  },
  closemask() {
    this.setData({
      showmask: false
    })
  },
  catchtap() {},


  change_name(e) {
    this.setData({
      name: e.detail.value,
      list: [],
      page: 1,
      flag: true,
    })
    this.getauntList()
  },

})